package org.szy.core.common.config;

import cn.beecp.BeeDataSource;
import cn.beecp.BeeDataSourceConfig;
import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.audit.ConsoleMessageCollector;
import com.mybatisflex.core.audit.MessageCollector;
import com.mybatisflex.core.mybatis.FlexConfiguration;
import org.apache.ibatis.solon.annotation.Db;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;

/**
 * 配置数据源
 *
 * @author 孙志阳
 * @date 2023-06-13
 * @since 1.0.0
 **/
@Configuration
public class DbConfig {

//    @Bean(name = "db", typed = true)
//    public DataSource db(@Inject("${mysql.db1}") HikariDataSource ds) {
//        return ds;
//    }

    @Bean(value = "db", typed = true)
    public BeeDataSource dataSource(@Inject("${mysql.db1}") BeeDataSourceConfig config) {
        return new BeeDataSource(config);
    }

    @Bean
    public void DbConf(@Db("db") FlexConfiguration cfg) {
        cfg.setCacheEnabled(false);
    }

}
